package org.tgcloud.group.web.controller.manager;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.custom.Permissions;
import org.tgcloud.group.core.session.Session;
import org.tgcloud.group.service.manager.BusinessManageService;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author: zhy
 * @create: 2023-09-27 09:13
 * @description: 商务管理相关接口
 */
@Api(tags = "商务管理相关接口")
@RestController
@RequestMapping("/manager/pc/user")
@EnableAutoConfiguration
public class BusinessManageController extends ManageAPPBaseController{

    @Autowired
    private BusinessManageService businessManageService;

//    @Permissions("business:view")
    @ApiOperation(value = "商务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/getBusinessList", method = RequestMethod.POST)
    public APPResultMessage getBusinessList(@ModelAttribute("session") Session session,
                                            @RequestParam(required = false) Integer pageNum,
                                            @RequestParam(required = false) Integer pageSize,
                                            @RequestParam(required = false) String keyword,
                                            @RequestParam(required = false) Short status,
                                            @RequestParam(required = false) Long startTime,
                                            @RequestParam(required = false) Long endTime,
                                            @RequestParam(required = false) Integer gradeId,
                                            @RequestParam(required = false) String area,
                                            @RequestParam(required = false) Short businessType,
                                            @RequestParam(required = false) Integer departId,
                                            @RequestParam(required = false) Integer groupId,
                                            @RequestParam(required = false) Integer areaId,
                                            @RequestParam(required = false) Long chooseShowStartMonth,
                                            @RequestParam(required = false) Long chooseShowEndMonth){
        return businessManageService.getBusinessList(pageNum, pageSize, keyword, status,
                startTime == null ? null : new Date(startTime), endTime == null ? null : new Date(endTime),
                gradeId, area, businessType, departId,groupId,areaId,session.getComId(),
                chooseShowStartMonth == null ? null : new Date(chooseShowStartMonth),
                chooseShowEndMonth == null ? null : new Date(chooseShowEndMonth));
    }



    @Permissions("business:add")
    @ApiOperation(value = "添加商务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/addBusiness", method = RequestMethod.POST)
    public APPResultMessage doAddBusiness(@ModelAttribute("session") Session session,
                                            @RequestParam String username,
                                            @RequestParam String telephone,
                                            @RequestParam BigDecimal basicSalary,
                                            @RequestParam BigDecimal performanceGoodsValue,
                                            @RequestParam String internalValue,
                                            @RequestParam Integer gradeId,
                                          @RequestParam String area,
                                          @RequestParam(required = false) Long joinTime,
                                          @RequestParam short businessType,
                                          @RequestParam Integer departId,
                                          @RequestParam Integer groupId,
                                          @RequestParam Integer teamType,
                                          @RequestParam(required = false) String performanceTime,
                                          @RequestParam(required = false) String performanceTimeList,
                                          @RequestParam(required = false) Integer businessAssistantId,
                                          @RequestParam(required = false) String productSelectionUserIds,
                                          @RequestParam(required = false) String customValue
                                          ){
        return businessManageService.doAddBusiness(username, telephone, basicSalary, performanceGoodsValue, internalValue,gradeId, area,
                joinTime == null ? null : new Date(joinTime), businessType, departId,groupId,teamType,performanceTime, performanceTimeList,
                businessAssistantId, productSelectionUserIds, customValue);
    }


    @Permissions("business:edit")
    @ApiOperation(value = "编辑商务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/editBusiness", method = RequestMethod.POST)
    public APPResultMessage doEditBusiness(@ModelAttribute("session") Session session,
                                          @RequestParam int businessId,
                                          @RequestParam(required = false) String username,
                                          @RequestParam(required = false) String telephone,
                                          @RequestParam(required = false) BigDecimal basicSalary,
                                          @RequestParam(required = false) BigDecimal performanceGoodsValue,
                                          @RequestParam(required = false) String internalValue,
                                          @RequestParam(required = false) Integer gradeId,
                                           @RequestParam(required = false) String area,
                                           @RequestParam(required = false) Long joinTime,
                                           @RequestParam(required = false) String password,
                                           @RequestParam(required = false) Short businessType,
                                           @RequestParam(required = false) Integer departId,
                                           @RequestParam Integer groupId,
                                           @RequestParam Integer teamType,
                                           @RequestParam(required = false) String performanceTime,
                                           @RequestParam(required = false) String performanceTimeList,
                                          @RequestParam(required = false) Integer businessAssistantId,
                                           @RequestParam(required = false) String productSelectionUserIds,
                                           @RequestParam(required = false) String customValue
                                           ){
        return businessManageService.doEditBusiness(businessId, username, telephone, basicSalary, performanceGoodsValue, internalValue,gradeId, area,
                joinTime == null ? null : new Date(joinTime), password, businessType, departId,groupId,teamType,performanceTime, performanceTimeList,
                businessAssistantId, productSelectionUserIds, customValue);
    }


    @Permissions("business:editStatus,business:delStatus")
    @ApiOperation(value = "编辑商务状态---辞职---编外")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/editBusinessStatus", method = RequestMethod.POST)
    public APPResultMessage doEditBusinessStatus(@ModelAttribute("session") Session session,
                                           @RequestParam int businessId,
                                           @RequestParam Short status,
                                                 @RequestParam(required = false) Long departTime){
        return businessManageService.doEditBusinessStatus(businessId, status,departTime == null ? null : new Date(departTime));
    }


    @ApiOperation(value = "查看商务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/getBusinessMsg", method = RequestMethod.POST)
    public APPResultMessage doGetBusinessMsg(@ModelAttribute("session") Session session,
                                             @RequestParam(required = false) Long startTime,
                                             @RequestParam(required = false) Long endTime,
                                             @RequestParam int businessId){
        return businessManageService.doGetBusinessMsg(startTime == null ? null : new Date(startTime),
                endTime == null ? null : new Date(endTime), businessId);
    }


    @Permissions("business:resetPassword")
    @ApiOperation(value = "编辑商务密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/resetBusinessPassword", method = RequestMethod.POST)
    public APPResultMessage doEditResetBusinessPassword(@ModelAttribute("session") Session session,
                                                 @RequestParam int businessId){
        return businessManageService.doEditResetBusinessPassword(businessId);
    }


    @Permissions("business:selectPerformance")
    @ApiOperation(value = "查看商务绩效")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/selectPerformanceList", method = RequestMethod.POST)
    public APPResultMessage selectPerformanceList(@ModelAttribute("session") Session session,
                                                  @RequestParam(required = false) Integer pageNum,
                                                  @RequestParam(required = false) Integer pageSize,
                                                  @RequestParam int businessId){
        return businessManageService.selectPerformanceList(pageNum,pageSize,businessId);
    }


    @Permissions("business:addPerformance")
    @ApiOperation(value = "新增修改商务绩效")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "string")
    })
    @ResponseBody
    @RequestMapping(value = "/doAddPerformanceList", method = RequestMethod.POST)
    public APPResultMessage doAddPerformanceList(@ModelAttribute("session") Session session,
                                                 @RequestParam int businessId,
                                                 @RequestParam String performanceTimeList){
        return businessManageService.doAddPerformanceList(businessId, performanceTimeList);
    }


}
